package com.example;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by v_chenqi02 on 2016/11/10.
 */

@RestController
public class ComputerController {

    Log log = LogFactory.getLog(ComputerController.class);

    @Autowired
    DiscoveryClient client;

    @RequestMapping("/del")
    public String delete(int a, int b, HttpServletRequest request) {

        log.info("接收到请求，来自"+ request.getRemoteAddr() );

        if( client != null ) {
            log.info( "服务描述："+client.description() );

            ServiceInstance serviceInstance = client.getLocalServiceInstance();

            log.info("getServiceId ：" + serviceInstance.getServiceId() + "\tgetHost" + serviceInstance.getHost()
                    + "\tgetMetadata:" + serviceInstance.getMetadata());
        }

        return a-b+"";

    }

}
